<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>创建数组</title>
</head>

<body>
  <script>
    // 数组字面量
    let a = [ , ]
    console.log(a.length);
    // 扩展操作符
    let b = 'wct10'
    let digits = [...b]
    console.log(digits);
    let c = 'aaaabbbbcccccss'
    // new Set集合对象
    let digits1 = [...new Set(c)]
    console.log(digits1);
    // Array()构造函数 缺点只有一个参数时，指定的是数组长度，无法创建只包含一个数值元素的数组
    let d = new Array(5)
    console.log(d);
    let e = new Array(5, 4, 3, 2, 1, "wct")
    console.log(e);
    // Array.of()可以解决以上的缺点 
    let d1 = Array.of(5)
    console.log(d1);
    // Array.from()
    // f是类数组
    //  Array.from(obj, mapFn, thisArg) 就相当于 Array.from(obj).map(mapFn, thisArg)
    let f = { length: 4, 0: 1, 2: 2, 1: 3, }
    console.log(f);
    let f1 = Array.from(f, x => x + 1)
    console.log(f1);


  </script>
</body>

</html>